/*
 * @(#)Top2012Result.java		       Project:Tools
 * Date:2012-12-26
 *
 * Copyright (c) 2012 CFuture09, Institute of Software, 
 * Guangdong Ocean University, Zhanjiang, GuangDong, China.
 * All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.sinaapp.msdxblog.tools.oschina;

import java.io.IOException;
import java.net.MalformedURLException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

/**
 * @author Geek_Soledad (66704238@51uc.com)
 */
public class Top2012Result {

	private static final String TOP_20_URL = "http://www.oschina.net/project/top_cn_2012";
	private static final int MY_POLL = 200;
	private static final String AGENT_NAME = "User-Agent";
	private static final String AGENT_VALUE = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2";

	public static void main(String[] args) {
		Document document;
		try {
			document = Jsoup.connect(TOP_20_URL)
					.header(AGENT_NAME, AGENT_VALUE).get();
			Elements elements = document.select("dd.num");
			int count = 0;
			for (Element element : elements) {
				if (Integer.parseInt(element.select("strong").first().text()) > MY_POLL) {
					count++;
				}
			}
			System.out.println(count + "/" + elements.size());
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
